import '@/styles/index.scss' // global css

import { createApp } from 'vue'
import App from './App.vue'
// 1. 导入路由的实例
import router from './router'

import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper'

// const app = createApp(App)
// //  2. 注册路由
// app.use(router)

// app.mount('#app')

// createApp(App).use(router).mount('#app')

// 使用乾坤渲染子应用
renderWithQiankun({
  // 挂载时
  mount(props) {
    console.log('大屏子应用挂载了！')
    render(props)
  },
  bootstrap() {
    console.log('大屏子应用启动了！')
  },
  unmount(props) {
    console.log('unmount', props)
  },
})

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render({})
}

function render(props = {}) {
  const { container } = props
  const app = createApp(App)
  app.use(router)
  app.mount(container ? container.querySelector("#app") : "#app")
}
